import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getList(this);
		},
		/**
		 * 打开导入文件弹窗
		 * @param {Number} type 打开类型 1 导入商品属性 2 导入裸石
		 */
		openImportFileDialogPop(type){
			const model = this.Model
			model.importFileDialog = true
			model.openImportType = type
		},
		//点击上传
		uploadExcel(){
			var apiTest = this.apiTest;
			let importUrl = `${apiTest}/supplier/supplierGoods/machining/importExcelList`
			if(this.Model.openImportType==2){
				importUrl = `${apiTest}/supplier/supplierGoods/looseStone/importExcelList`
			}
    		this.$ajax({
				method: 'post',
				url:importUrl,
				data:this.Model.upFileForm
			}).then((res)=>{
				if(res.data.status == 200){
					this.$message.success('导入成功')
					this.Model.importFileDialog=false
				}else{
					this.tips(this,'warning','导入失败！')
				}
			});
		},
		//选择文件
		fileChange(){
			var fileObj = document.getElementById("fileup").files[0];
			var form = new FormData();
			form.append("file", fileObj);
			this.Model.upFileForm = form;
			var that = this;
			var obj = document.getElementById("fileup");
			var len = obj.files.length;
			for (var i = 0; i < len; i++) {
				var temp = obj.files[i].name;
				that.Model.fileupName = temp;
			}
		},
		//批量送检
		qualityBatch(){
			let idList=[]
			let tableData = this.Model.selectedList
			this.Model.editDialogObsolete=false
			if(!tableData.length){
				this.$message.error('请勾选任意1条数据！')
				return
			}
			tableData.forEach(item=>{
				idList.push(item.id)
			})
			this.$ajax({
				method: 'post',
				url: `${this.apiTest}/supplier/supplierGoods/sendToCheck`,
				data:{
					goodsIdList:idList,
					qcAddress:this.Model.qcAddress
				}
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					this.$message.success('操作成功')
					this.getList(this)
				}else{
					this.$message.error(data.msg)
				}
			});
		},
		//获取列表
		getList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {};
			params.businessType=170
			var apiTest = this.apiTest;
			this.$ajax({
					method: 'post',
					url:`${apiTest}/supplier/supplierGoods/goodToCheckList`,
					data:{
						condition:params,
						pageIndex: pageIndex,
						pageSize: pageSize,
					}
			    }).then((res)=>{
					that.Model.tableData = [];
					var data = res.data;
					if(data.status == 200){
						var pagination = commonObject.paginationFunction(data.result);
						that.Model.paginationObject = objDeepCopy(pagination);
						var result = data.result.result;
						if(result){
							that.Model.tableData = result;
						}
					}else{
			
					}
				});
		},
		//详情
		toDetial(row) {
			this.$router.push({
				path:'giveQualityBarcodeDetailSole',
				query:{
					barCode:row.barCode
				}
			});
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.selectedList = val;
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,val);
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params);
		},
		toClear(val) {
			this.Model.searchFromData = {};
		},
		toExport(val) {
		  console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		objFilters:function(value){
			
		}
	}
}
export default Controller;
